package com.view.judge;

import com.dao.JudgeDao;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JudgeInsert {
    private JFrame jf=null;
    private JButton submit=new JButton("修改"); //修改
    private JLabel[] item=null;     //标题
    private JTextField[] jt=null;   //输入框
    private String[] value=null;    //值
    private JudgeDao cd =new JudgeDao();

    public JudgeInsert(){
        jf=new JFrame("裁判表查询");
        jf.setLayout(null); //绝对定位
        int height=20;  //窗口的高度
        String[][] all=cd.browsingData();


        int length=all[0].length-1; //列的个数，去掉id列
        item=new JLabel[length];
        value=new String[length];
        jt=new JTextField[length];
        String[] na=new String[length];
        for(int i=0;i<=length;i++){
            System.out.println(all[0][i]);
        }
        for(int i=0;i<=length-1;i++){
            na[i]=all[0][i+1];
            item[i]=new JLabel(na[i]);    //获取列名
            item[i].setSize(80,30); //
            item[i].setLocation(20,height);
            jf.add(item[i]);
            jt[i]=new JTextField();
            jt[i].setSize(150,30);
            jt[i].setLocation(130,height);
            jf.add(jt[i]);
            height+=40;
        }
        submit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(e.getSource()==submit){
                    for(int i=0;i<length;i++){
                        value[i]=jt[i].getText();
                    }
                    cd.addData(na,value);
                }
            }
        });
        submit.setSize(60,30);
        submit.setLocation(120,height);

        jf.add(submit);
        jf.setSize(300,height+80);
        jf.setVisible(true);
    }
}
